home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16541 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  110 lines

  1. Path: news.flex.com.au!news
  2. From: cobweb@flex.com.au (Tony L)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help Please
  5. Date: Thu, 11 Apr 1996 03:53:06 GMT
  6. Organization: Flex Information Technology
  7. Message-ID: <4ki39v$30s@daisy.flex.com.au>
  8. NNTP-Posting-Host: slip1-12.flex.com.au
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hi all,
  12.  
  13. The following is a very simple little program that I'm doing.
  14.  
  15. Could someone please have a quick look through it and please tell me
  16. how I can get the 10th option to work.  I can't figure out what to do
  17. if a person chooses number 10.  I know that it is not refered to as a
  18. character seeing it contains 2 chars.  But I'm lost  :-)
  19.  
  20. btw, could you also just quickly tell me if I have declared everything
  21. ok.  Should "weight" and "total" be declared as a "float"?
  22.  
  23. Also, I know I'm pushing my luck here asking sooo many questions, but
  24. could you also please tell me what is the best way to make the program
  25. loop.  Should I use a "do... while loop", or do I just need a "while"
  26. loop?
  27.  
  28. Thank you very much for your help....
  29.  
  30. //  This Program allows a person to enter their weight and it will
  31. //  output their weight on other Planets....
  32.  
  33. #include <stdio.h>
  34. #include <conio.h>
  35.  
  36. main()
  37. {
  38.     char first[25], last[25];
  39.     float weight, total;
  40.     char choice;
  41.  
  42.     clrscr();
  43.     textcolor(YELLOW);cprintf(" Weighing On Different Planets");
  44.     printf("\n\nWhat is your first name please? ");
  45.     scanf(" %s", first);
  46.     printf("\nWhat is your last name please? ");
  47.     scanf("  %s", last);
  48.     printf("\nGreetings, %s %s! How many pounds do you weight? ", first,
  49. last);
  50.     scanf(" %f", &weight);
  51.     printf("\nPick the number of the Planet you want to weigh in on:\n ");
  52.     printf("\n          1. Mercury    6. Saturn"  );
  53.     printf("\n          2. Venus        7. Uranus"  );
  54.     printf("\n          3. Earth        8. Neptune" );
  55.     printf("\n          4. Mars                 9. Pluto  " );
  56.     printf("\n          5. Jupiter               10. The Moon");
  57.  
  58.     printf("\n\nPlease select a number: ");
  59.     scanf(" %c", &choice);
  60.     switch (choice)
  61.      {    case ('1') :    total = (weight * .4);
  62.             printf("On Mercury you would weigh %.2f Pounds", total);
  63.             break;
  64.     case ('2') :    total = (weight * .9);
  65.             printf("On Venus you would weigh %.2f Pounds", total);
  66.             break;
  67.     case ('3') :    printf("On Earth you would weigh %.2f Pounds of
  68. course", weight);
  69.             break;
  70.     case ('4') :    total = (weight * .4);
  71.             printf("On Mars you would weigh %.2f Pounds", total);
  72.             break;
  73.     case ('5') :    total = (weight * 2.5);
  74.             printf("On Venus you would weigh %.2f Pounds", total);
  75.             break;
  76.     case ('6') :    total = (weight * .9);
  77.             printf("On Saturn you would weigh %.2f Pounds", total);
  78.             break;
  79.     case ('7') :    total = (weight * .8);
  80.             printf("On Uranus you would weigh %.2f Pounds", total);
  81.             break;
  82.     case ('8') :    total = (weight * 1.2);
  83.             printf("On Neptune you would weigh %.2f Pounds", total);
  84.             break;
  85.     case ('9') :    total = (weight * .06);
  86.             printf("On Pluto you would weigh %.2f Pounds", total);
  87.             break;
  88.     case ('10') :   total = (weight * .17);
  89.             printf("On the Moon you would weigh %.2f Pounds", total);
  90.             break;
  91.  
  92.     default    : printf("That's an INVALID Request sorry!");
  93.      }
  94.  
  95.     return 0;
  96. }
  97.  
  98. Once again, thank you....
  99.  
  100.  
  101.  Regards,
  102.  TonyL....
  103.  
  104. =-=-=-=-=-=-=-=-=-=-=-=-=-
  105. E-mail: cobweb@flex.com.au
  106.         lamborghini@acslink.net.au
  107. URL:    http://www.peg.apc.org/~lamborghini  
  108. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  109.  
  110.